﻿#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string multiply(string num1, string num2)
    {
        if (num1 == "0" || num2 == "0")
        {
            return "0";
        }
        int n = num1.size();
        int m = num2.size();
        auto arr = vector<int>(n + m);//auto的类型
        for (int i = n - 1; i >= 0; --i)
        {
            int value1 = num1[i] - '0';
            for (int j = m - 1; j >= 0; --j)
            {
                int value2 = num2[j] - '0';
                arr[i + j + 1] += value1 * value2;
            }
        }
        for (int i = n + m - 1; i > 0; --i)
        {
            if (arr[i] >= 10)
            {
                arr[i - 1] += arr[i] / 10;
                arr[i] %= 10;
            }
        }
        string s1;
        int index = arr[0] == 0 ? 1 : 0;
        while (index < m + n)
        {
            s1.push_back(arr[index++] + '0');
        }
        return s1;
    }
};
